# -*- coding:utf-8 -*-

import commands
from core import network


def host_ip():
    os_info = commands.getoutput("cat /etc/redhat-release").split("Linux")
    os_info = "".join(os_info).split()
    release = os_info[2].strip()
    # print release
    release = release.split(".")[0].strip()
    ipconfig = commands.getoutput("ifconfig -a")
    raw_data = ipconfig.split("\n")
    if release == "7":
        nic_list = network.centos7(raw_data)
    else:
        nic_list = network.centos6(raw_data)

    host_inner = dict()
    record_host = None
    for record in nic_list:
        if record['ipaddress']:
            if record['ipaddress'].startswith('10'):
                record_host = record['ipaddress']
                break
            else:
                record_host = record['ipaddress']
    return record_host